package com.sunnada.edu.system.pub.util;


import java.util.Properties;

import org.springframework.beans.factory.FactoryBean;

public class DataSourceFac implements FactoryBean{
	public String param;
	
	public String getParam() {
		return param;
	}

	public void setParam(String param) {
		this.param = param;
	}

	@Override
	public Object getObject() throws Exception {
		 if (param != null) {  
	            return String.valueOf(DES3.decrypt(param));  
	        } else {  
	            return null;  
	        }  
	}

	@SuppressWarnings("unused")
	private String deEncryptString(String originalString) {
		StringBuilder newString = new StringBuilder();
		for (int i = 0; i < originalString.length(); ++i) {
			char eachChar = originalString.charAt(i);
			char newChar = (char) (eachChar + i);
			newString.append(newChar);
		}
		return newString.toString();
	}

	private String encryptString(String str) {
		String result = "";
		try {
			byte[] strByte = str.getBytes();
			for (int i = 0; i < str.length(); ++i)
				if (strByte[i] <= 40)
					result = result + (char) (strByte[i] + 10);
				else if ((strByte[i] > 40) && (strByte[i] <= 80))
					result = result + (char) (strByte[i] + 50);
				else if ((strByte[i] > 80) && (strByte[i] <= 120))
					result = result + (char) (strByte[i] - 30);
				else if (strByte[i] > 120)
					result = result + (char) (strByte[i] + 6);
		} catch (Exception e) {
			System.err.println("加密出错,出错原因=" + e.toString());
			result = "-1";
		}
		return result;
	}


	@Override
	public Class getObjectType() {
		return String.class;
	}



	@Override
	public boolean isSingleton() {
		return true;
	}



}